import Qs from "qs";

export const addCommodity = (vm, id) => {
  let data = {
    commodityId: id,
    suserId: vm.$store.state.userInfo.id
  }
  vm.$axios.post('/collection/add', data)
    .then((res) => {
      vm.$message.success("收藏成功")
      vm.$store.commit('setCollectionCount')
    })
}
export const getCollectionInfo = (vm, id) => {
  let data = Qs.stringify({
    userId: id
  });
  vm.$axios.post('/collection/userid', data)
    .then((res) => {
      //console.log(res)
      vm.$store.state.collectionCount = res.data.data.length
    })
}

export const getCollectionInfoDetail = (vm) => {
  let data = Qs.stringify({
    userId: vm.$store.state.userInfo.id
  });
  vm.$axios.post('/collection/userid', data)
    .then((res) => {
      console.log(res)
      vm.tableData = res.data.data
      vm.isFlag = res.data.data.length
      vm.$store.state.collectionCount = res.data.data.length
    })
}

export const deleteCollectionInfo = (vm, id) => {
  let data = [id]
  vm.$axios.delete('/collection/id?collectionids=' + data)
    .then((res) => {
     vm.$message.success('删除成功')
      getCollectionInfoDetail(vm)
    })
}
